import Vue from 'vue'
import Router from 'vue-router'
import {RouteRoleList} from "./dict";
import { getUserInfo } from "../utils/auth";

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/index/index'),
        meta: { title: '首页', icon: 'svghome' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  {
    path: '/class-management',
    component: Layout,
    meta: {
      title: '',
      icon: 'school'
    },
    children: [
      {
        path: 'class',
        component: () => import('@/views/class-management/class'),
        name: 'Class',
        meta: { title: '课程' }
      },
      {
        path: 'class-children',
        component: () => import('@/views/class-management/class-children'),
        name: 'Class-children',
        meta: { title: '设置子课程' },
        hidden: true
      },
      {
        path: 'class-baoming',
        component: () => import('@/views/class-management/class-baoming'),
        name: 'Class-baoming',
        meta: { title: '报名学员列表' },
        hidden: true
      }
    ]
  },
  {
    path: '/teacher-management',
    component: Layout,
    meta: {
      title: '',
      icon: 'coach'
    },
    children: [
      {
        path: 'teacher',
        component: () => import('@/views/teacher-management/teacher'),
        name: 'Teacher',
        meta: { title: '主讲老师' }
      },
      {
        path: 'teacher-class',
        component: () => import('@/views/teacher-management/teacher-class'),
        name: 'Teacher-class',
        meta: { title: '主讲课题' },
        hidden: true
      }
    ]
  },
  {
    path: '/learnCard-management',
    component: Layout,
    meta: {
      title: '',
      icon: 'manager'
    },
    children: [
      {
        path: 'learnCard',
        component: () => import('@/views/learnCard-management/learnCard'),
        name: 'learnCard',
        meta: { title: '学习卡用户' }
      },
      {
        path: 'userRecord',
        component: () => import('@/views/learnCard-management/userRecord'),
        name: 'userRecord',
        meta: { title: '已报名列表' },
        hidden: true
      },
      {
        path: 'cardRecord',
        component: () => import('@/views/learnCard-management/cardRecord'),
        name: 'CardRecord',
        meta: { title: '学习卡记录' },
        hidden: true
      }
    ]
  },
  {
    path: '/order-management',
    component: Layout,
    meta: {
      title: '',
      icon: 'list'
    },
    children: [
      {
        path: 'order',
        component: () => import('@/views/order-management/order'),
        name: 'Order',
        meta: { title: '小程序订单'}
      }
    ]
  },
  {
    "path": '/order-offline',
    component: Layout,
    meta: {
      title: '线下购买',
      icon: 'order'
    },
    redirect: '/order-offline/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/order-offline/list'),
        name: "list",
        meta: {title: '线下购买'}
      },
      {
        path: 'info',
        component: () => import('@/views/order-offline/info'),
        name: "info",
        meta: {title: '订单详情'},
        hidden: true,
      },
      {
        path: 'add',
        component: () => import('@/views/order-offline/add'),
        name: "add",
        meta: {title: '添加订单'},
        hidden: true,
      },
    ]
  },
  {
    path: '/subject-management',
    component: Layout,
    meta: {
      title: '',
      icon: 'manager'
    },
    children: [
      {
        path: 'subject',
        component: () => import('@/views/subject-management/subject'),
        name: 'subject',
        meta: { title: '课堂评价', }
      }
    ]
  },
  {
    path: '/cooperation-management',
    component: Layout,
    meta: {
      title: '',
      icon: 'reward'
    },
    children: [
      {
        path: 'cooperation',
        component: () => import('@/views/cooperation-management/cooperation'),
        name: 'cooperation',
        meta: { title: '合作企业' }
      },
      {
        path: 'companyRecord',
        component: () => import('@/views/cooperation-management/companyRecord'),
        name: 'companyRecord',
        meta: { title: '上课成员' },
        hidden: true,
      }
    ]
  },
  {
    path: "/feed-back",
    component: Layout,
    meta: {
      title: '意见反馈',
      icon: 'feedBack',
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/feedback/list'),
        name: 'feed-list',
        meta: {title:'意见反馈'}
      }
    ]
  },
  {
    path: '/setting-management',
    component: Layout,
    meta: {
      title: '设置',
      icon: 'setting',
    },
    children: [
      {
        path: 'alert-setting',
        component: () => import('@/views/setting-management/alert-setting'),
        name: 'alert-setting',
        meta: { title: '弹窗活动设置' }
      },
      {
        path: 'swiper-setting',
        component: () => import('@/views/setting-management/swiper-setting'),
        name: 'swiper-setting',
        meta: { title: '轮播图活动设置' }
      },
      {
        path: 'enterprise-setting',
        component: () => import('@/views/setting-management/enterprise-setting'),
        name: 'enterprise-setting',
        meta: { title: '企业年卡项目设置' }
      },
      {
        path: 'evaluation-setting',
        component: () => import('@/views/setting-management/evaluation-setting'),
        name: 'evaluation-setting',
        meta: { title: '课后评价问题设置' }
      },
      {
        path: 'add-evaluation',
        component: () => import('@/views/setting-management/add-evaluation'),
        name: 'add-evaluation',
        hidden: true,
        meta: { title: '课后评价问题设置' }
      }
    ]
  },
]

var  userInfo = getUserInfo();

var  complexRoutes = constantRoutes;

// if (userInfo) {
//   if (userInfo.school_id == 0) {
//     complexRoutes = constantRoutes.concat(RouteRoleList.superAdmin);
//   } else {
//     complexRoutes = constantRoutes.concat(RouteRoleList.schoolAdmin);
//   }
// } else {
//   complexRoutes = constantRoutes;
// }

const createRouter = () => new Router({
  //mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
